{extend name="public:base"}
{block name='css'}
<link href="__PUBLIC__/css/plugins/iCheck/custom.css" rel="stylesheet">
{/block}
{block name="js"}
<script src="__PUBLIC__/js/content.min.js?v=1.0.0"></script>
<script src="__PUBLIC__/js/plugins/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/plugins/validate/messages_zh.min.js"></script>
<script type="text/javascript">
	//获取下级市列表
	function getAjaxRegion(id,name){
		if(!id){
			return false;
		}

		if (name == 'city_id') {
			$("select[name=city_id]").html('<option value="">请选择</option>');
			$("select[name=area_id]").html('<option value="">请选择</option>');
		} else {
			$("select[name=area_id]").html('<option value="">请选择</option>');
		}

		$.ajax( {
			url:"{:url('Index/getAjaxRegion')}",
			data:{
				'id' : id
			},
			type:'get',
			cache:false,
			dataType:'json',
			success:function(data) {
				if(data.status == 'y'){
					var html='<option value="">请选择</option>';
					for(var i in data.info){
						html+='<option value="'+data.info[i].id+'">'+data.info[i].title+'</option>';
					}
					if(data.info.length){
						$("select[name='"+name+"']").html(html);
					}else{
						$("select[name='"+name+"']").html('<option value="">没有找到城市！</option>');
					}

				}else{
					layer.msg(data.info);
				}
			}
		});

	}

	$.validator.setDefaults({
		highlight: function(e) {
			$(e).closest(".form-group").removeClass("has-success").addClass("has-error")
		},
		success: function(e) {
			e.closest(".form-group").removeClass("has-error").addClass("has-success")
		},
		errorElement: "span",
		errorPlacement: function(e, r) {
			e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
		},
		errorClass: "help-block m-b-none",
		validClass: "help-block m-b-none"
	});
	$().ready(function() {
		var e = "<i class='fa fa-times-circle'></i> ";
		$("#commentForm").validate({
			rules: {
				username:{
					required:true,
					minlength:3
				},
				password: {
					required:true,
					minlength:5
				},
				group_id: "required",
				truename: "required"
//				tel: "required"
			},
			messages: {
				username:{
					required:e + "请输入登录帐号",
					minlength:e + "登录帐号长度不能少于3"
				},
				password: {
					required:e + "请输入登录密码",
					minlength:e + "登录密码长度不能少于5"
				},
				group_id: e + "请选择用户组",
				truename: e + "请输入姓名"
//				tel: e + "请选择联系电话"
			},
			submitHandler: function(form){
				if ($(form).hasClass('ed')) {
					return false;
				}

				$(form).addClass('ed');
				var obj = showMyLoading();
				$.post('', $(form).serialize(), function(data){
					hideMyLoading(obj);
					layer.msg(data.info);
					if (data.status == 'y') {
						window.location.href = '{:url("index")}';
					} else {
						$(form).removeClass('ed');
					}
				}, 'json');
			},
			invalidHandler: function(form, validator) {  //不通过回调
				return false;
			}
		})
	});
</script>
{/block}
{block name='body'}

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>添加管理员</h5>
                        <a href="javascript:history.go(-1);" class="btn btn-sm btn-primary pull-right m-t-n-xs">返回</a>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="commentForm" action="" enctype="multipart/form-data" >
                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户登录帐号</label>
                                <div class="col-sm-10">
                                    <input type="text" name="username" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户登录密码</label>
                                <div class="col-sm-10">
                                    <input type="text" name="password" class="form-control">
                                </div>
                            </div>
							<div class="form-group">
                                <label class="col-sm-2 control-label">用户组</label>
                                <div class="col-sm-10">
                                    <select class="form-control m-b" name="group_id" style="margin:0px;">
                                        <option value="">请选择！</option>
										{foreach name="groupList" item="li"}
                                        	<option value="{$li.id}">{$li.title}</option>
										{/foreach}
									</select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">姓名</label>
                                <div class="col-sm-10">
                                    <input type="text" name="truename" class="form-control">
                                </div>
                            </div>
							<div class="form-group">
                                <label class="col-sm-2 control-label">联系电话</label>
                                <div class="col-sm-10">
                                    <input type="text" name="tel" class="form-control" >
                                </div>
                            </div>
							<div class="form-group">
                                <label class="col-sm-2 control-label">省市区</label>
                                <div class="col-sm-10">
                                    <div class="col-sm-3" style="padding-left:0px;">
										<select class="form-control m-b" name="sheng_id" onchange="getAjaxRegion(this.value,'city_id')" style="margin-bottom:0px;">
											<option value="">请选择省！</option>
											{foreach name="shengList" item="sheng"}
	                                         	<option value="{$sheng.id}" >{$sheng.title}</option>
                                        	{/foreach}
										</select>
									</div>
									<div class="col-sm-3">
										<select class="form-control m-b" name="city_id" onchange="getAjaxRegion(this.value,'area_id')" style="margin-bottom:0px;">
											<option value="">请选择市！</option>
										</select>
									</div>
									<div class="col-sm-3">
										<select class="form-control m-b" name="area_id" style="margin-bottom:0px;">
											<option value="">请选择市！</option>
										</select>
									</div>
                                </div>
                            </div>
							<div class="form-group">
                                <label class="col-sm-2 control-label">街道地址</label>
                                <div class="col-sm-10">
                                    <input type="text" name="address" class="form-control">
                                </div>
                            </div>
							
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">保存内容</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>
{/block}
